import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PetArenaRewardInfo } from "../../../resource/info/PetArenaRewardInfo";
import { Language } from "../../../../../extend/language/Language";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { PetCpnRewardUtil } from "./info/PetCpnRewardUtil";
import { SReward } from "../../../../../Message/Public/SReward";
import { Tooltip } from "../../common/tooltip/Tooltip";
import { LayerManager } from "../../../manager/LayerManager";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class PetCpnRankRewardItem
    
    export  class PetCpnRankRewardItem /* flash.display.Sprite */
    {
        constructor(arg1: string="", arg2: Object /* flash.text.TextFormat */=null)
        {
            
            this._rankStr = arg1;
            this._tft = arg2;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._rankTxt = ObjCreate.createTextField(this._rankStr, 0, 0, 200, 20, this, this._tft);
            this._rankTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemTxt = ObjCreate.createTextField("", 75, 0, 200, 20, this);
            this._itemTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemTxt.addEventListener(flash.events.TextEvent.LINK, this.onItemClickHandler);
            this._rewardTxt = ObjCreate.createTextField("", 110, 0, 200, 20, this, GlobalStyle.textFormatOrange);
            this._rewardTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            return;
        }

        public updateReward(arg1: PetArenaRewardInfo, arg2: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            this._rewardInfo = arg1;
            if (arg1) 
            {
                if (arg2) 
                {
                    if (arg1.rankMax > 5000) 
                    {
                        this._rankTxt.htmlText = Language.getStringByParam(54693, arg1.rank);
                    }
                    else 
                    {
                        this._rankTxt.htmlText = Language.getStringByParam(54694, arg1.rank, arg1.rankMax);
                    }
                }
                else 
                {
                    this._itemTxt.x = 0;
                }
                loc1 = arg1.itemDataArray;
                loc2 = arg1.rewardArray;
                if (loc1.length > 0) 
                {
                    loc3 = "";
                    loc5 = "";
                    loc6 = 0;
                    while (loc6 < loc1.length) 
                    {
                        loc4 = loc1[loc6] as ItemData;
                        if (loc6 != (loc1.length - 1)) 
                        {
                            loc5 = " ";
                        }
                        loc3 = loc3 + ("<a href=\'event:" + loc6 + "\'>" + ItemsUtil.getItemNameAndAmount(loc4) + "</a>" + loc5);
                        ++loc6;
                    }
                    this._itemTxt.htmlText = loc3;
                    this._rewardTxt.x = this._itemTxt.x + this._itemTxt.width + 10;
                }
                else 
                {
                    this._rewardTxt.x = 75;
                }
                if (loc2.length > 0) 
                {
                    loc7 = "";
                    loc8 = 0;
                    while (loc8 < loc2.length) 
                    {
                        loc7 = loc7 + ("+" + PetCpnRewardUtil.getStrByReward(loc2[loc8] as SReward, "", false) + "  ");
                        ++loc8;
                    }
                    this._rewardTxt.htmlText = loc7;
                }
            }
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=int(arg1.text);
            var loc2=this._rewardInfo.itemDataArray[loc1] as ItemData;
            if (!PetCpnRankRewardItem._toolTip) 
            {
                PetCpnRankRewardItem._toolTip = new Tooltip();
                PetCpnRankRewardItem._closeBtn = ObjCreate.createGButton("", PetCpnRankRewardItem._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                PetCpnRankRewardItem._spTooltipContainer.addChild(PetCpnRankRewardItem._toolTip);
                PetCpnRankRewardItem._spTooltipContainer.addChild(PetCpnRankRewardItem._closeBtn);
            }
            PetCpnRankRewardItem._toolTip.data = loc2.getToolTipData();
            PetCpnRankRewardItem._spTooltipContainer.x = localToGlobal(new Object /* flash.geom.Point */(this._itemTxt.x, 0)).x + this._itemTxt.width;
            PetCpnRankRewardItem._spTooltipContainer.y = localToGlobal(new Object /* flash.geom.Point */(0, this._itemTxt.y)).y + this._itemTxt.height;
            LayerManager.toolTipLayer.addChild(PetCpnRankRewardItem._spTooltipContainer);
            PetCpnRankRewardItem._closeBtn.x = PetCpnRankRewardItem._toolTip.width - 24;
            PetCpnRankRewardItem._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            return;
        }

        /* internal  */closeTootipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (PetCpnRankRewardItem._spTooltipContainer && PetCpnRankRewardItem._spTooltipContainer.parent) 
            {
                PetCpnRankRewardItem._spTooltipContainer.parent.removeChild(PetCpnRankRewardItem._spTooltipContainer);
            }
            return;
        }

        /* internal */ /* var */_rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rankStr: string;

        /* internal */ /* var */_tft: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_rewardInfo: PetArenaRewardInfo;

        /* internal */ static /* var */_closeBtn: GButton;

        /* internal */ static /* var */_toolTip: Tooltip;

        /* internal */ static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;
    }

            PetCpnRankRewardItem._spTooltipContainer = new Object /* flash.display.Sprite */();
        